package com.czp.javasetsail.controller;

import com.czp.javasetsail.entity.User;
import com.czp.javasetsail.mapper.UserMapper;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author 陈振平
 * @create 2021-08-18 3:02 下午
 */
@RestController
@RequestMapping("test")
public class TestController {

    @Autowired(required=false)
    private UserMapper userMapper;

    @GetMapping("selectList")
    public String selectList(){
        return "Hello World!";
//       List<User> list = userMapper.selectList(null);
//       list.forEach(System.out::println);
//       return list;
    }


    @GetMapping("save")
    public void save(){
        User user = new User();
        user.setUsername("小陈");
        user.setPassword("234567");
        user.setAge(16);
        userMapper.insert(user);
        System.out.println(user);
    }

    @GetMapping("update")
    public void update(){
        User userDto = userMapper.selectById(7);
        userDto.setUsername("小王");
        userMapper.updateById(userDto);
    }

    @Test
    public void time(){
        DateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(time);

        //构建明天凌晨的时间
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, 1);
        String time1 = new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(cal.getTime());
        System.out.println(cal.getTime());
        System.out.println(time1);

        // 获取当前时间-12小时
        String time2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
        System.out.println(time2);

        // 获取当前时间-24小时
        String time3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println(time3);

    }
}
